﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_group_user_fv.ascx.vb"
    Inherits="Apps_Shares_Uc_group_user_fv" %>
<asp:FormView ID="fv" runat="server" RenderOuterTable="False" DefaultMode="Edit"
    DataSourceID="fvSrc" EnableModelValidation="True" Width="100%">
    <InsertItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อกลุ่มผู้ใช้งาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtGroupName' runat='server' Text='<%# Bind("group_user_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        หน่วยงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlStpDepartment' runat='server' AppendDataBoundItems="True"
                            DataSourceID="ddlStpDepartmentSrc" DataTextField="department_name" DataValueField="department_code"
                            SelectedValue='<%# Bind("department_code") %>'>
                            <asp:ListItem Text='หน่วยงาน' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:HiddenField ID='hideDepartment_code' runat='server' Value='<%# Bind("department_code") %>' />
                        <asp:ObjectDataSource ID="ddlStpDepartmentSrc" runat="server" SelectMethod="GetStpDepartmentByPrivilege"
                            TypeName="CodeMatrix.Business.GenericData">
                        </asp:ObjectDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภท <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID="ddlAdminType" runat="server" AppendDataBoundItems="True"
                            DataSourceID="ddlAdminTypeSrc" DataTextField="group_user_type_name" 
                            DataValueField="group_user_type" SelectedValue='<%# Bind("group_user_type") %>'
                            onselectedindexchanged="ddlAdminType_SelectedIndexChanged"
                            AutoPostBack="True">
                            <asp:ListItem Text='ประเภท' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlAdminTypeSrc" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:GHBankConnectionString %>" 
                            ProviderName="<%$ ConnectionStrings:GHBankConnectionString.ProviderName %>" 
                            SelectCommand="Select * from group_user_type"></asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        จำนวนวันที่หมดอายุรหัสผ่าน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtExpire' runat='server' Width="40px" MaxLength="3" ReadOnly="true" Text='<%# Bind("group_user_password_expire") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout='Flow'
                            SelectedValue='<%# Bind("group_user_status") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Insert" ValidationGroup='g1' />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="ddlStpDepartmentRequiredFieldValidator1" runat="server"
                                ControlToValidate="ddlStpDepartment" ErrorMessage="กรุณาเลือกหน่วยงาน" ValidationGroup="g1"
                                InitialValue="0"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="txtGroupNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtGroupName" ErrorMessage="กรุณากรอกชือกลุ่มผู้ใช้งาน" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="txtExpireRequiredFieldValidator" runat="server" ControlToValidate="txtExpire"
                                InitialValue='' ErrorMessage="กรุณาเลือกจำนวนวันที่หมดอายุรหัสผ่าน" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlAdminTypeRequiredFieldValidator" runat="server"
                                ControlToValidate="ddlAdminType" ValidationGroup='g1' ErrorMessage="กรุณาเลือกประเภทการใช้งาน"
                                InitialValue="0"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox='true'
                                ValidationGroup="g1" />
                    </td>
                </tr>
            </tbody>
        </table>
    </InsertItemTemplate>
    <EditItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อกลุ่มผู้ใช้งาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtGroupName' runat='server' Text='<%# Bind("group_user_name", "{0}") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        หน่วยงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlStpDepartment' runat='server' AppendDataBoundItems="True"
                            DataSourceID="ddlStpDepartmentSrc" DataTextField="department_name" 
                            DataValueField="department_code" SelectedValue='<%# Bind("department_code") %>'>
                            <asp:ListItem Text='หน่วยงาน' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:HiddenField ID='hideDepartment_code' runat='server' Value='<%# Bind("department_code") %>' />
                        <asp:ObjectDataSource ID="ddlStpDepartmentSrc" runat="server" SelectMethod="GetStpDepartmentByPrivilege"
                            TypeName="CodeMatrix.Business.GenericData">
                        </asp:ObjectDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภท <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID="ddlAdminType" runat="server" AppendDataBoundItems="True"
                            DataSourceID="ddlAdminTypeSrc" DataTextField="group_user_type_name" 
                            DataValueField="group_user_type" SelectedValue='<%# Bind("group_user_type") %>'
                            onselectedindexchanged="ddlAdminType_SelectedIndexChanged"
                            AutoPostBack="True">
                            <asp:ListItem Text='ประเภท' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlAdminTypeSrc" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:GHBankConnectionString %>" 
                            ProviderName="<%$ ConnectionStrings:GHBankConnectionString.ProviderName %>" 
                            SelectCommand="Select * from group_user_type"></asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        จำนวนวันที่หมดอายุรหัสผ่าน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtExpire' runat='server' Width="40px" MaxLength="3" ReadOnly="true" Text='<%# Bind("group_user_password_expire") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout='Flow'
                            SelectedValue='<%# Bind("group_user_status", "{0}") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Update" ValidationGroup="g1" />
                        <asp:Button ID='btnCancel' runat='server' Text='ยกเลิก' PostBackUrl="~/Apps/group_user_list.aspx?Edit=true" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="ddlStpDepartmentRequiredFieldValidator1" runat="server"
                                ControlToValidate="ddlStpDepartment" ErrorMessage="กรุณาเลือกหน่วยงาน" ValidationGroup="g1"
                                InitialValue="0"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="txtGroupNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtGroupName" ErrorMessage="กรุณากรอกชือกลุ่มผู้ใช้งาน" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="txtExpireRequiredFieldValidator" runat="server" ControlToValidate="txtExpire"
                                ErrorMessage="กรุณาเลือกจำนวนวันที่หมดอายุรหัสผ่าน" ValidationGroup="g1" InitialValue=''></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlAdminTypeRequiredFieldValidator" runat="server"
                                ControlToValidate="ddlAdminType" ValidationGroup='g1' ErrorMessage="กรุณาเลือกประเภทการใช้งาน"
                                InitialValue="0"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ValidationGroup="g1"
                                ShowMessageBox='true' />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </EditItemTemplate>
    <ItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อกลุ่มผู้ใช้งาน :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtGroupName' runat='server' Text='<%# Bind("group_user_name", "{0}") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        หน่วยงาน :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ddlStpDepartment' runat='server' Text='<%#CodeMatrix.Business.GenericData.GetDepartmentLabel(me,Eval("department_code")) %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภท :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ddlAdminType' runat='server' Text='<%# Eval("group_user_type_name") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        จำนวนวันที่หมดอายุรหัสผ่าน :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtExpire' runat='server' Text='<%# Bind("group_user_password_expire", "{0}") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='rblStatus' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetStatusLabel(Eval("group_user_status")) %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnCancel' runat='server' Text='ย้อนกลับ' PostBackUrl="~/Apps/group_user_list.aspx" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                    </td>
                </tr>
            </tbody>
        </table>
    </ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="fvSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
    InsertCommand="
        insert into group_user 
        (group_user_name,group_user_password_expire,group_user_type,group_user_status,staff_code_create,create_datetime,staff_code_update,update_datetime,department_code)
        values
        (@group_user_name,@group_user_password_expire,@group_user_type,@group_user_status,@staff_code,getdate(),@staff_code,getdate(),@department_code);" 
    SelectCommand="
        select 
            g.* , gtype.*,
		    Creator = dbo.UFN_GetAuditor(staff_code_create,create_datetime) ,
		    Editor = dbo.UFN_GetAuditor(staff_code_update,update_datetime) 
		from group_user g 
		inner join group_user_type gtype on g.group_user_type = gtype.group_user_type
		where g.group_user_code = @group_user_code"
    UpdateCommand="
        update	group_user
        set 
                group_user_name = @group_user_name , 
		        group_user_password_expire = @group_user_password_expire ,
		        group_user_type = @group_user_type ,
		        group_user_status = @group_user_status ,
		        staff_code_update = @staff_code_update ,
		        update_datetime = getdate(),
		        department_code = @department_code
        where   group_user_code = @group_user_code;">
    <InsertParameters>
        <asp:SessionParameter Name="staff_code" SessionField="staff_code" />
        <asp:Parameter Name="group_user_name" />
        <asp:Parameter Name="group_user_password_expire" />
        <asp:Parameter Name="group_user_type" />
        <asp:Parameter Name="group_user_status" />
        <asp:Parameter Name="department_code" />
    </InsertParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="group_user_code" QueryStringField="Edit" />
    </SelectParameters>
    <UpdateParameters>
        <asp:QueryStringParameter Name="group_user_code" QueryStringField="Edit" />
        <asp:SessionParameter Name='staff_code_update' SessionField='staff_code' />
    </UpdateParameters>
</asp:SqlDataSource>
<%  If Not fv.FindControl("txtExpire") Is Nothing Then%>

<script type="text/javascript">
    $(document).ready(function() {
        $('#' + '<%=fv.FindControl("txtExpire").ClientID %>').keypress(function(e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                return false;
            }
        });
    });
</script>

<%  End If%>